<style lang='less' scoped>
    @import '~style/filter.less';
    .rightContBigBox{
        position: relative;
        width: 100%;
    }
    .dataBox{
        margin-top: 20px;
        text-align: center;
    }
    .paginationBox{
        float: right;
        margin-top: 20px;
    }
</style>

<template>
    <div class="rightContBigBox">
        <filter-box
            v-show='this.$route.name == "privatePlacementList"'
            :issuerList='issuerList'
            :getButtonConfig='getButtonConfig'
            v-on:setFilterParams='setFormParams'
        ></filter-box>

        <table-box
            v-show='this.$route.name == "privatePlacementList"'
            :issuerList='issuerList'
            :formData='formData'
            :totalSize='totalSize'
            :getButtonConfig='getButtonConfig'
            v-on:setTableParams='setFormParams'
            v-on:reloadPage='reloadPage'
        ></table-box>

        <div v-show='this.$route.name == "privatePlacementListCheck" || this.$route.name == "privatePlacementListEdit" || this.$route.name =="privatePlacementListChangeStatus"'>
            <transition >
                <router-view
                    v-on:setTitleMsg='setTitleMsg'
                ></router-view>
            </transition>
        </div>

    </div>
</template>

<script>
    import filterBox from './filterBox.vue'
    import tableBox from './tableBox.vue'
    import {getIssuerId} from 'api/common'
    import {getPPList} from 'api/privatePlacement'

    export default {
        props:[],
        components:{
            filterBox,
            tableBox,
        },
        data(){
            return{
                issuerList:[],//发行方
                formQueryData:{
                    orderBy:'id',
                    xsc:'ASC'
                },
                totalSize:0,
                formData:[]
                
            }
        },
        computed:{
            getButtonConfig(){
                console.log('index:  computed getButtonConfig', this.$store.getters.getButtonConfig('privatePlacementList'))
                return this.$store.getters.getButtonConfig('privatePlacementList')
            },
        },
        watch:{
            $route:function(val, oldV){
                if(oldV.name =='privatePlacementListEdit' && val.name =='privatePlacementList'){
                    this.reloadPage()
                }
            }
        },
        methods:{
            async getIssuerId(){
                try{
                    let back = await getIssuerId()
                    back = back.data;
                    console.log('getIssuerId',back)
                    if(back && back.resultCode ==='200'){
                        this.issuerList = back.result;
                    }else{
                        this.$message({
                            message: '发行方获取失败' + back.msg,
                            type: 'warning'
                        });
                    }
                }catch(err){
                    this.$message({
                            message: '发行方获取失败！',
                            type: 'warning'
                        });
                    console.error(err)
                }
            },
            setParams(obj1){//部分请求参数不能传空值！
                let {keys} = Object, params={};
                for(let key of Object.keys(obj1)){
                    // console.log(key, obj1[key])
                    if(obj1[key]){
                    params[key] = obj1[key]
                    }
                }
                return params
            },
            setFormParams(e){
                console.log('setFormParams', e, this.formQueryData)
                Object.assign(this.formQueryData, e)
                this.getDataList(this.formQueryData)
            },
            async getDataList(params){
                try{
                    let obj = this.setParams(params)
                    let back = await getPPList(obj)
                    back = back.data;
                    console.log('getDataList', back)
                    if(back && back.resultCode =='200'){
                        this.formData = back.result;
                        this.totalSize = back.size
                    }
                }catch(err){
                    console.error(err)
                }
            },
            reloadPage(){
                console.log('重载页面了！')
                this.getDataList(this.formQueryData)

            },
            goPage(name, parm={}, query={}){
                // console.log(name)
                this.$router.push({
                    name: name,
                    params:parm,
                    query:query,
                })
            },
            setTitleMsg(msg){
                this.$emit('setTitleMsg' , msg)
            }
        },
        created(){
            this.setTitleMsg(['产品管理', '私募产品'])
            this.getIssuerId()
        },
  }
</script>